package com.tarry.controller;

import com.google.common.collect.Maps;
import com.tarry.bean.PageQuery;
import com.tarry.bean.PageResult;
import com.tarry.common.Result;
import com.tarry.model.entity.SysUser;
import com.tarry.model.vo.UserVo;
import com.tarry.service.SysTreeService;
import com.tarry.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.Map;

@Controller
@RequestMapping("/sys/user")
public class SysUserController {

    @Autowired
    private SysUserService sysUserService;
    @Autowired
    private SysTreeService sysTreeService;
    @Autowired
    //private SysRoleService sysRoleService;

    @RequestMapping("/noAuth.do")
    public ModelAndView noAuth() {
        return new ModelAndView("noAuth");
    }

    @RequestMapping("/save.json")
    @ResponseBody
    public Result saveUser(UserVo param) {
        sysUserService.save(param);
        return Result.success();
    }

    @RequestMapping("/update.json")
    @ResponseBody
    public Result updateUser(UserVo param) {
        sysUserService.update(param);
        return Result.success();
    }

    @RequestMapping("/page.json")
    @ResponseBody
    public Result page(@RequestParam("deptId") int deptId, PageQuery pageQuery) {
        PageResult<SysUser> result = sysUserService.getPageByDeptId(deptId, pageQuery);
        return Result.success(result);
    }

//    @RequestMapping("/acls.json")
//    @ResponseBody
//    public Result acls(@RequestParam("userId") int userId) {
//        Map<String, Object> map = Maps.newHashMap();
//        map.put("acls", sysTreeService.userAclTree(userId));
//        map.put("roles", sysRoleService.getRoleListByUserId(userId));
//        return Result.success(map);
//    }
}
